package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eItemId;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.yearMaster.YearMasterMgr;

import java.util.ArrayList;
import java.util.List;

public class YearMasterRecycleStrategy extends AbstractItemRecycleStrategy {
    @Override
    public void markNeedRecycleItem() {
        ActivityInfo activityInfo = YearMasterMgr.getActivityInfo();
        if (activityInfo != null) {
            long recycleTime = activityInfo.getEndShowTime() * 1000 + 600 * 1000;
            ActivityItemRecycleMgr.addRecycleItemData(eItemId.YEAR_MASTER_FIREWORKS.getValue(), activityType, recycleTime);

            recycleTime = activityInfo.getEndTime() * 1000L + 600 * 1000;
            List<String> paramList = new ArrayList<>();
            paramList.add(String.valueOf(eItemId.YEAR_MASTER_EGG.getValue()));
            paramList.add(String.valueOf(eItemId.YEAR_MASTER_SCORE.getValue()));
            paramList.add("2");
            paramList.add(activityInfo.getActivityName());
            ActivityItemRecycleMgr.addRecycleItemData(eItemId.YEAR_MASTER_EGG.getValue(), activityType, 1, recycleTime, paramList);
        }
    }

    @Override
    public boolean isActivityRunning() {
        ActivityInfo activityInfo = YearMasterMgr.getActivityInfo();
        return ActivityMgr.activityInTime(activityInfo);
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.YearMasterActivity.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        int itemId = data.getItemId();
        int recycleType = data.getRecycleType();
        if (recycleType == 0) {
            UserBagItem userBagItem = getUserBagItem(userId, itemId);
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        } else if (recycleType == 1) {
            item2Score(userId, data, MailManager.YEAR_MASTER_ACTIVITY_GOODS_AUTO_CONSUME_TITLE, MailManager.YEAR_MASTER_ACTIVITY_GOODS_AUTO_CONSUME_CONTENT);
        }
    }

}
